package lgkj.meicqt20.view;

import android.content.Context;
import android.net.Uri;
import android.util.AttributeSet;
import android.util.Log;
import android.widget.VideoView;

import java.util.HashMap;
import java.util.Map;

import lgkj.meicqt20.utils.HttpUtils;

/**
 * Created by Administrator on 2017/12/25 0025.
 */

public class CustomVideoView extends VideoView {
    private String Tag = "CustomVideoView";

    public CustomVideoView(Context context) {
        super(context);
    }

    public CustomVideoView(Context context, AttributeSet attrs) {
        super(context, attrs, 0);
    }

    public CustomVideoView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }


    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        //我们重新计算高度
//        int width = getDefaultSize(0, widthMeasureSpec);
//        int height = getDefaultSize(0, heightMeasureSpec);
        setMeasuredDimension(1024, 750);
    }

    public void play(Uri url) {
//        url=Uri.parse("http://lianguang.oss-cn-shanghai.aliyuncs.com/adadddefualt/1514268062_1752996313.mp4");
        Map<String, String> map = new HashMap<>();
        map.put(HttpUtils.httpHederKey, HttpUtils.httpHederValue);
        setVideoURI(url, map);
        start();
    }

    @Override
    public void onWindowFocusChanged(boolean hasWindowFocus) {
        if (hasWindowFocus) {
            start();
            Log.d(Tag, "onWindowFocusChanged:" + "true");
        } else {
            pause();
            Log.d(Tag, "onWindowFocusChanged:" + "false");
        }
        super.onWindowFocusChanged(hasWindowFocus);
    }
}
